import {
  exportUrl,
  getLineCodeList,
  getFactoryCodeList,
  getStopStatusList,
  getIsCommonList,
  getGoodsList,
  getStopTypeList,
} from "@/api/configuration/mesPmJtmanager";
// 列表头按钮配置
export const operateList = [
  {
    name: $i18n.t("common.export"),
    type: "primary",
    icon: "el-icon-download",
    handleName: "export", //点击时返回的标识
    url: exportUrl,
    //auth: "auth:operlog:export", //权限字段
  },
  {
    name: $i18n.t("common.add"),
    type: "primary",
    icon: "el-icon-circle-plus-outline",
    handleName: "add", //点击时返回的标识
  },

  {
    name: $i18n.t("common.delete"),
    type: "danger",
    icon: "el-icon-delete",
    handleName: "deleteBatch", //点击时返回的标识
    isMultiple: true,
  },
  {
    name: $i18n.t("mesPmJtmanager.recover"),
    type: "success",
    icon: "el-icon-s-promotion",
    isMultiple: true, //至少选择一条
    //是否可点击；
    disabled: (data) => {
      let bomStatus = data[0]?.stopStatus ?? "";
      return data.length != 1 || bomStatus == 0;
    },
    handleName: "resume", //点击时返回的标识
  },
];
// 行末按钮配置
export const rowConfig = [
  {
    name: $i18n.t("common.edit"),
    type: "primary",
    class: "row-btn-primary",
    handleName: "edit", //点击时返回的标识
  },
  {
    name: $i18n.t("common.details"),
    type: "info",
    class: "row-btn-info",
    handleName: "detail", //点击时返回的标识
  },
  {
    name: $i18n.t("common.delete"),
    type: "danger",
    class: "row-btn-danger",
    handleName: "delete", //点击时返回的标识
  },
];
// 搜索条件配置
export const searchConfig = {
  data() {
    const self = this;
    return {
      searchDialog: {
        inline: true,
        formDesc: {
          prodCode: {
            type: "input",
            label: $i18n.t("mesPmJtmanager.prodCode2"),
          },
          lineCode: {
            type: "select",
            label: $i18n.t("mesPmJtmanager.line"),
            prop: {
              value: "modelingCode",
              text: "modelingName",
            },
            options: async (data) => {
              const params = {
                modelingCode: self.$store.getters.factoryCode,
                level: 5,
              };
              const list = await getLineCodeList(params);
              return list.data.result;
            },
          },
          stopStatus: {
            label: $i18n.t("mesPmJtmanager.stopStatus"),
            type: "select",

            prop: {
              value: "value",
              text: "description",
            },
            options: async (data) => {
              const list = await getStopStatusList();
              return list.data.result;
            },
          },
          // factoryCode: {
          //   type: "select",
          //   label: "工厂",
          //   type: "select",
          //   prop: {
          //     value: "modelingCode",
          //     text: "modelingName",
          //   },
          //   options: async (data) => {
          //     const list = await getFactoryCodeList();
          //     return list.data.result;
          //   },
          // },
          // responsePersion: {
          //   type: "input",
          //   label: "停机类型",
          // },
          // repairMethod: {
          //   type: "input",
          //   label: "停机原因",
          // },
          // resolvent: {
          //   type: "input",
          //   label: "解决方案",
          // },
          // sourceType: {
          //   type: "input",
          //   label: "数据来源0:cosmo,1:api",
          // },
          // prodVersion: {
          //   type: "input",
          //   label: "产品版本号",
          // },
          // isCommon: {
          //   type: "radio",
          //   label: "是否通用",
          //   type: 'select',
          //   prop: {
          //     value: "value",
          //     text: "description",
          //   },
          //   options: async (data) => {
          //     const list = await getIsCommonList()
          //     return list.data.result
          //   },
          // },
          // remark: {
          //   type: "input",
          //   label: "备注",
          // },
        },
      },
    };
  },
};
// 新增/删除表单配置
export const formDescDialogMinxin = {
  data() {
    const self = this;
    return {
      formDescDialog: {
        span: 24,
        disabled: false,
        isShowSubmitBtn: true,
        formDesc: {
          // factoryCode: {
          //   type: "select",
          //   label: "工厂",
          //   layout: 12,
          //   required: true,
          //   prop: {
          //     value: "modelingCode",
          //     text: "modelingName",
          //   },
          //   options: async (data) => {
          //     const list = await getFactoryCodeList();
          //     return list.data.result;
          //   },
          // },
          lineCode: {
            type: "select",
            label: $i18n.t("mesPmJtmanager.line"),
            layout: 12,
            required: true,
            prop: {
              value: "modelingCode",
              text: "modelingName",
            },
            options: async () => {
              const params = {
                modelingCode: this.$store.getters.factoryCode,
                level: 5,
              };
              const list = await getLineCodeList(params);
              const data = list.data.result;
              console.log(data);
              self.lineCodeList = data;
              return data;
            },
            on: {
              change: (val) => {
                console.log(val);
                const findItem =
                  self.lineCodeList.find((item) => item.modelingCode == val) ||
                  {};
                self.$set(
                  self.formDataDialog,
                  "lineName",
                  findItem.modelingName || ""
                );
              },
            },
          },
          prodCode: {
            type: "select",
            label: $i18n.t("mesPmJtmanager.prodCode"),
            layout: 12,
            required: true,
            prop: {
              value: "goodsCode",
              text: "goodsName",
            },
            options: async () => {
              const list = await getGoodsList();
              const data = list.data.result;
              console.log(data);
              self.prodCodeList = data;
              return data;
            },
            // on: {
            //   change: (val) => {
            //     console.log(val);
            //     const findItem =
            //       self.prodCodeList.find((item) => item.goodsCode == val) || {};
            //     self.$set(
            //       self.formDataDialog,
            //       "prodName",
            //       findItem.goodsName || ""
            //     );
            //     console.log(self.formDataDialog);
            //   },
            // },
          },
          responsePersion: {
            type: "select",
            label: $i18n.t("mesPmJtmanager.stopType"),
            layout: 12,
            required: true,
            prop: {
              value: "description",
              text: "description",
            },
            options: async (data) => {
              const list = await getStopTypeList();
              return list.data.result;
            },
          },
          repairMethod: {
            type: "input",
            label: $i18n.t("mesPmJtmanager.repairMethod"),
            layout: 12,
            required: true,
          },
          resolvent: {
            type: "input",
            label: $i18n.t("mesPmJtmanager.resolvent"),
            layout: 12,
            required: true,
          },
          // sourceType: {
          //   type: "input",
          //   label: "数据来源",
          //   layout: 12,
          //   required: false,
          // },
          stopStatus: {
            type: "select",
            label: $i18n.t("mesPmJtmanager.stopStatus"),
            layout: 12,
            required: false,
            prop: {
              value: "value",
              text: "description",
            },
            options: async (data) => {
              const list = await getStopStatusList();
              return list.data.result;
            },
          },
          prodVersion: {
            type: "input",
            label: $i18n.t("mesPmJtmanager.prodVersion"),
            layout: 12,
            required: false,
          },
          isCommon: {
            type: "select",
            label: $i18n.t("mesPmJtmanager.isCommon"),
            layout: 12,
            required: false,
            prop: {
              value: "value",
              text: "description",
            },
            options: async (data) => {
              const list = await getIsCommonList();
              return list.data.result;
            },
          },
          remark: {
            type: "textarea",
            label: $i18n.t("common.remark"),
            layout: 24,
            required: false,
          },
        },
      },
    };
  },
};
// 恢复按钮 表单配置
export const formResumeMinxin = {
  data() {
    const self = this;
    return {
      formResumeMinxinDialog: {
        span: 24,
        disabled: false,
        isShowSubmitBtn: true,
        formDesc: {
          /* lineCode: {
            type: "select",
            label: "线体",
            layout: 12,
            required: true,
            disabled: true,
            prop: {
              value: "modelingCode",
              text: "modelingName",
            },
            options: async () => {
              const params = {
                modelingCode: this.$store.getters.factoryCode
              }
              const list = await getLineCodeList(params);
              const data = list.data.result;
              console.log(data);
              self.lineCodeList = data;
              return data;
            },

          },
          prodCode: {
            type: "select",
            label: "产品",
            disabled: true,
            layout: 12,
            required: true,
            prop: {
              value: "goodsCode",
              text: "goodsName",
            },
            options: async () => {
              const list = await getGoodsList();
              const data = list.data.result;
              console.log(data);
              self.prodCodeList = data;
              return data;
            },
            // on: {
            //   change: (val) => {
            //     console.log(val);
            //     const findItem =
            //       self.prodCodeList.find((item) => item.goodsCode == val) || {};
            //     self.$set(
            //       self.formDataDialog,
            //       "prodName",
            //       findItem.goodsName || ""
            //     );
            //     console.log(self.formDataDialog);
            //   },
            // },
          },
          responsePersion: {
            type: "select",
            label: "停机类型",
            disabled: true,
            layout: 12,
            required: true,
            prop: {
              value: "description",
              text: "description",
            },
            options: async (data) => {
              const list = await getStopTypeList();
              return list.data.result;
            },
          },
          repairMethod: {
            type: "input",
            label: "停机原因",
            disabled: true,
            layout: 12,
            required: true,
          },

          prodVersion: {
            type: "input",
            label: "产品版本号",
            disabled: true,
            layout: 12,
            required: false,
          },
          isCommon: {
            type: "select",
            label: "是否委外工序",
            disabled: true,
            layout: 12,
            required: false,
            prop: {
              value: "value",
              text: "description",
            },
            options: async (data) => {
              const list = await getIsCommonList();
              return list.data.result;
            },
          },*/
          resolvent: {
            type: "textarea",
            label: $i18n.t("mesPmJtmanager.resolvent"),
            layout: 12,
            required: true,
          },

          remark: {
            type: "textarea",
            label: $i18n.t("common.remark"),
            layout: 12,
            required: false,
          },
        },
      },
    };
  },
};
